package com.lt.ltmng.converter;

import org.zkoss.bind.BindContext;
import org.zkoss.bind.Converter;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;

public class ListEntryConverter implements Converter<Listitem, Integer, Listbox> {

	public Listitem coerceToUi(Integer val, Listbox component, BindContext ctx) {
		if(val != null)
			for(Listitem item : component.getItems()) {
				if(val.toString().equals(String.valueOf(item.getValue())))
					return item;
			}
		return null;
	}

	public Integer coerceToBean(Listitem val, Listbox component, BindContext ctx) {
		return val == null ? null : Integer.parseInt(String.valueOf(val.getValue()));
	}
}
